package com.szbber.medical.ui.fragment.setting

import android.os.Bundle
import android.view.View
import androidx.core.widget.addTextChangedListener
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.orhanobut.logger.Logger
import com.szbber.commen.base.BaseApplication
import com.szbber.commen.base.BaseFragment
import com.szbber.commen.base.BaseVMFragment
import com.szbber.commen.bean.DialogClickBean
import com.szbber.commen.dialog.DialogUtils
import com.szbber.commen.utils.PreferUtil
import com.szbber.medical.R
import com.szbber.medical.databinding.FragmentPortSettingBinding
import com.szbber.medical.viewmodel.SplashViewmodel
import com.szbber.medical.viewmodel.fragment.PortSettingViewModel
import kotlinx.android.synthetic.main.fragment_port_setting.*
import java.util.concurrent.TimeUnit

/**
 * @author: Administrator
 * @date: 2022/4/18
 */
class PortSettingFragment : BaseVMFragment<FragmentPortSettingBinding, PortSettingViewModel>(),
    View.OnClickListener {

    companion object {
        fun getInstance(): PortSettingFragment {
            return PortSettingFragment()
        }
    }

    override fun initVM(): PortSettingViewModel =
        ViewModelProvider(this, ViewModelProvider.NewInstanceFactory()).get(
            PortSettingViewModel::class.java
        )

    override fun getLayoutResId(): Int = R.layout.fragment_port_setting

    override fun initView(savedInstanceState: Bundle?) {

        mBinding.portSettingModel = mViewModel
        mViewModel.getDeviceType(activity)
        mViewModel.getServiceIP(activity)
        mViewModel.getHospitalInfo()
        mViewModel.getDeptInfo()
        mViewModel.getDistrictInfo()
        mViewModel.getRoomInfo()
        mViewModel.getBedInfo()

        tvDeviceType.setOnClickListener(this)
        cvHospital.setOnClickListener(this)
        cvDept.setOnClickListener(this)
        cvDistrict.setOnClickListener(this)
        cvRoom.setOnClickListener(this)
        cvBed.setOnClickListener(this)

        etServiceIp.addTextChangedListener {
            mViewModel.setServiceIP(it.toString())
        }

    }

    override fun onClick(v: View?) {
        when (v?.id) {

            R.id.cvHospital -> mViewModel.getHospitalBean(activity)
            R.id.cvDept -> mViewModel.getDeptBean(activity)
            R.id.cvDistrict -> mViewModel.getDistrictBean(activity)
            R.id.cvRoom -> mViewModel.getRoomBean(activity)
            R.id.cvBed -> mViewModel.getBedBean(activity)




            R.id.tvDeviceType -> {
                DialogUtils.showCheckDeviceDialog(activity){
                    it.itemBean?.id?.apply { mViewModel.setDeviceType(activity, this)
                    }
                }
            }
        }
    }


}